package cn.fan.xxljob.config;

//import com.xxl.job.core.util.ShardingUtil;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;



@Component
@Slf4j
public class UserJob {


    @XxlJob("testHandler")
    public ReturnT<String> testHandler(String param) throws Exception {
        log.info("立可得集成xxl-job");
        return ReturnT.SUCCESS;
    }


    @XxlJob("supplyJobHandler")
    public ReturnT<String> supplyJobHandler(String param) throws  Exception{
        //获取分片总数和当前分片索引  2.2.0写法
//        ShardingUtil.ShardingVO shardingVo = ShardingUtil.getShardingVo();
//        int numbers = shardingVo.getTotal();  //分片总数
//        int index = shardingVo.getIndex(); //当前分片索引
//        log.info("分片参数  当前分片索引{}   总分片数{}",index,numbers);
//2.3.0写法
        int shardIndex = XxlJobHelper.getShardIndex();
        int shardTotal = XxlJobHelper.getShardTotal();

//        QueryWrapper<VendingMachineEntity> qw=new QueryWrapper<>();
//        qw.lambda()
//                .eq(VendingMachineEntity::getVmStatus, VMSystem.VM_STATUS_RUNNING)
//                .apply("mod(id,"+numbers+" ) = "+index);  //对id取模
//        List<VendingMachineEntity> vmList = vmService.list(qw);

        return ReturnT.SUCCESS;
    }

}
